import { applyMiddleware, createStore } from 'redux'
// 导入合并后的 rootReducer
import rootReducer from './reducers'
// import logger from 'redux-logger'
import thunk from 'redux-thunk'
import { composeWithDevTools } from 'redux-devtools-extension'

// thunk 中间件核心源码：
// const thunk = (store) => (next) => (action) => {
//   // 如果接收的 action 是函数，调用这个函数并传递 dispatch
//   if (typeof action === 'function') {
//     return action(store.dispatch, store.getState)
//   }
//   // 如果是普通 action 直接 next(action) 进入下一个中间件
//   return next(action)
// }

// 基于合并后的 rootReducer 创建仓库实例
const store = createStore(rootReducer, composeWithDevTools(applyMiddleware(thunk)))

export default store
